package yass.drawcard;

import android.content.Intent;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.view.View;
import android.widget.GridView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import java.lang.ref.SoftReference;
import java.util.Random;

import de.hdodenhof.circleimageview.CircleImageView;
import yass.drawcard.base.BaseActivity;
import yass.drawcard.utils.ShanHaiUtil;
import yass.drawcard.utils.ViewUtil;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private static final RequestOptions BANNER_OPTIONS = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .dontAnimate()
            // .fitCenter()
            .centerCrop();

    private RelativeLayout backBtn;
    private RelativeLayout confirmBtn;
    private AppCompatTextView confirmTv;
    private CircleImageView backTv;
    private AppCompatTextView titleTv;


    /**
     * 接收子线程消息的 Handler
     */
    public static class MyHandler extends Handler {

        // 软引用
        SoftReference<MainActivity> fragmentRef;

        public MyHandler(MainActivity fragment) {
            fragmentRef = new SoftReference<MainActivity>(fragment);
        }

        @Override
        public void handleMessage(Message msg) {
            MainActivity fragment = fragmentRef.get();
            if (fragment == null) {
                return;
            }
            Bundle bundle = msg.getData();

            // 处理UI 变化
            switch (msg.what) {
                /*case ConstValues.WAIT1:// // 获取分类列表的回调
                    fragment.getJsonSuc(bundle);
                    break;*/
            }
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();
    }

    private void initView() {

        backBtn = (RelativeLayout) findViewById(R.id.main_navigation_rl_back);
        confirmBtn = (RelativeLayout) findViewById(R.id.main_navigation_rl_confirm);
        confirmTv = (AppCompatTextView) findViewById(R.id.main_navigation_bt_confirm);
        backTv = (CircleImageView) findViewById(R.id.main_navigation_bt_back);
        titleTv = (AppCompatTextView) findViewById(R.id.main_navigation_tv_title);
        confirmBtn.setVisibility(View.INVISIBLE);
        confirmBtn.setVisibility(View.VISIBLE);
        confirmBtn.setOnClickListener(this);
        backBtn.setOnClickListener(this);

    }


    private void initData() {

        titleTv.setText("首页");

        // 设置默认http
        String httpid = ShanHaiUtil.getHttpid();
        if (TextUtils.isEmpty(httpid)) {
            ShanHaiUtil.putHttpid("http://psa3hbhy.ipyingshe.net/");
        } else {

        }

        // 头像
        Glide.with(MainActivity.this)
                .load(R.mipmap.ic_launcher_b)
                .apply(BANNER_OPTIONS)
                .into(backTv);

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.main_navigation_rl_back://
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent intent = new Intent(this, MineActivity.class);
                startActivity(intent);

                break;
            case R.id.main_navigation_rl_confirm://
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                break;
        }
    }
}
